//
//  PopoverBootcamp_30.swift
//  SwiftUiExercise
//
//  Created by 徐鹏 on 2023/7/2.
//

//sheets
//animations
//transitions

import SwiftUI

struct PopoverBootcamp_30: View {
    
    @State var showNewScreen: Bool = false

    
    var body: some View {
        ZStack{
            Color.orange
                .edgesIgnoringSafeArea(.all)
            
            VStack{
                Button("BUTTON") {
                    showNewScreen.toggle()
                }
                .font(.largeTitle)
                Spacer()
            }
//            .sheet(isPresented: $showNewScreen) {
//                NewScreen()
//            }
            
//            if showNewScreen{
//                NewScreen(showNewScreen: $showNewScreen)
//                    .padding(.top,100)
//                    .transition(.move(edge: .bottom))
//                    .animation(.spring())
//            }
            
            
//            if showNewScreen{
//                NewScreen(showNewScreen: $showNewScreen)
//                    .padding(.top,100)
//                    .transition(.move(edge: .bottom))
//                    .animation(.spring())
//            }

             NewScreen(showNewScreen: $showNewScreen)
                .padding(.top,100)
                .offset(y: showNewScreen ? 0 : UIScreen.main.bounds.height)
                .animation(.spring())


        }
    }
}

struct NewScreen: View{
    
    @Environment(\.presentationMode) var presentationMode
    @Binding var showNewScreen: Bool
    
    var body: some View{
        ZStack(alignment:.topLeading){
            Color.purple
                .edgesIgnoringSafeArea(.all)
            
            Button {
                //presentationMode.wrappedValue.dismiss()
                showNewScreen.toggle()
            } label: {
                Image(systemName: "xmark")
                    .foregroundColor(.white)
                    .font(.largeTitle)
                    .padding(20)
            }

        }
    }
}

struct PopoverBootcamp_30_Previews: PreviewProvider {
    static var previews: some View {
        PopoverBootcamp_30()
    }
}
